@extends('backend.layouts.base')
@section('title', '存储设置')
@section('content')
    <div class="all">
        <div id="app" v-cloak>
            <el-form ref="form" :model="form" :rules="rules" label-width="15%">
                <div class="vue-head head-tab-con">
                    <el-radio-group v-model="display_type">
                        <el-radio-button label="1" @click.native="gotoOther(1)">全局设置</el-radio-button>
                        <el-radio-button label="2" @click.native="gotoOther(2)">远程存储设置</el-radio-button>
                    </el-radio-group>
                </div>
                <div class="vue-head">
                    <div class="vue-main-title">
                        <div class="vue-main-title-left"></div>
                        <div class="vue-main-title-content">全局设置</div>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="支持图片后缀" prop="pic_suffix">
                            <el-input v-model="form.pic_suffix" :rows="5" type="textarea" ref="pic_suffix"></el-input>
                            <div class="tip">填写图片后缀名称，如：jpg，换行输入，一行一个后缀（如果为空，则采用系统默认设置）</div>
                        </el-form-item>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="支持图片大小" prop="pic_size">
                            <el-input v-model="form.pic_size" ref="pic_size">
                                <template slot="append">KB</template>
                            </el-input>
                        </el-form-item>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="支持音频后缀" prop="audio_suffix">
                            <el-input v-model="form.audio_suffix" :rows="5" type="textarea" ref="audio_suffix"></el-input>
                            <div class="tip">填写音视频后缀名称，如：mp3，换行输入，一行一个后缀（如果为空，则采用系统默认设置</div>
                        </el-form-item>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="支持音频大小" prop="audio_size">
                            <el-input v-model="form.audio_size" ref="audio_size">
                                <template slot="append">KB</template>
                            </el-input>
                        </el-form-item>
                    </div>
                </div>
            </el-form>
            <div class="vue-page">
                <div class="vue-center">
                    <el-button type="primary" @click="submitForm('form')">提交</el-button>
                    <el-button @click="goBack">返回</el-button>
                </div>
            </div>
        </div>
    </div>

    <script>
        var app = new Vue({
            el:"#app",
            delimiters: ['[[', ']]'],
            name: 'settingAttach',
            data() {
                return{
                    display_type:'1',
                    form:{
                        pic_suffix:'',
                        pic_size:'',
                        audio_suffix:'',
                        audio_size:''
                    },
                    rules:{
                    },
                }
            },
            created() {
            },
            mounted() {
                this.getData();
            },
            methods: {
                getData() {
                    let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
                    this.$http.post('{!! absolute_admin_url('sys.setting.attachInfo') !!}',{}).then(function (response) {
                            if (response.data.result){
                                this.form = {
                                    ...response.data.data,
                                };
                            }
                            else {
                                this.$message({message: response.data.msg,type: 'error'});
                            }
                            loading.close();
                        },function (response) {
                            this.$message({message: response.data.msg,type: 'error'});
                            loading.close();
                        }
                    );
                },
                submitForm(formName) {
                    console.log(this.form)
                    let that = this;
                    let json = {
                        pic_suffix:this.form.pic_suffix,
                        pic_size:this.form.pic_size,
                        audio_suffix:this.form.audio_suffix,
                        audio_size:this.form.audio_size
                    };

                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                            let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
                            this.$http.post('{!! absolute_admin_url('sys.setting.attachSave') !!}',{setting:json}).then(response => {
                                if (response.data.result) {
                                    this.$message({type: 'success',message: '操作成功!'});
                                } else {
                                    this.$message({message: response.data.msg,type: 'error'});
                                }
                                loading.close();
                            },response => {
                                this.$message({message: response.data.msg,type: 'error'});
                                loading.close();
                            });
                        }
                        else {
                            console.log('error submit!!');
                            return false;
                        }
                    });
                },

                goBack() {
                    history.go(-1)
                },
                gotoOther(type) {
                    let url = ""
                    if(type==1) {
                        // url = ''
                    }else if(type==2) {
                        url = '{!! absolute_admin_url('sys.setting.remoteAttach') !!}'
                    }
                    if(url) {
                        window.location.href=url
                    }
                },
            },
        })

    </script>
@endsection
